import api from '../../api/index'
Page({
  data: {
    userInfo: {
      phone: '188888888',
      name: '',
    },
    classIndex: '',
    yearIndex: '',
    classList: [
      { id: 1, name: '一班' },
      { id: 1, name: '二班' },
      { id: 1, name: '3班' },
      { id: 1, name: '4班' },
    ],
    yearList: [
      { id: 1, name: '95' },
      { id: 1, name: '96' },
      { id: 1, name: '97' },
      { id: 1, name: '98' },
    ],
  },
  onLoad(options) {
    if (options) {
      this.setData({
        userInfo: options
      })
    }

  },
  onReady() {

  },
  onShow() {

  },
  bindPickerChange(e) {
    const { value } = e.detail
    const { name } = e.currentTarget.dataset
    console.log(e);
    this.setData({ [name]: value })
  },
  changeName(e) {
    const { value } = e.detail
    let userInfo = this.data.userInfo
    let name = e.currentTarget.dataset.name
    userInfo[name] = value
    this.setData({ userInfo })
  },
  submit() {
    const { userInfo, classIndex, yearIndex, yearList, classList } = this.data
    if (!userInfo.cardNum) {
      return wx.showToast({ icon: 'none', title: '请输入身份证号', })
    }
    if (!userInfo.userName) {
      return wx.showToast({ icon: 'none', title: '请输入用户姓名', })
    }
    if (yearIndex === '') {
      return wx.showToast({ icon: 'none', title: '请选择毕业时间', })
    }
    if (classIndex === '') {
      return wx.showToast({ icon: 'none', title: '请选择班级', })
    }
    const data = { ...userInfo, year: yearList[yearIndex].id, class: classList[classIndex] }
    api.user.schoolFellowSmart(data).then(res => {
      console.log(res)
    })
  },
})